package com.feifan.monthhelper.calculate;

import android.support.annotation.NonNull;

import com.feifan.monthhelper.bean.db.DayRecordBean;

import java.util.Date;

public class CalculateContext {
    MenstrualDayCalculate menstrualDayCalculate = new MenstrualDayCalculate();
    SafeDayCalculate safeDayCalculate = new SafeDayCalculate();
    OvulatoryDayCalculate ovulatoryDayCalculate = new OvulatoryDayCalculate();

    private int menstrual_period;
    private int span_period;
    private Date date;

    public CalculateContext(Date date, int menstrual_period, int span_period) {
        this.date = date;
        menstrualDayCalculate.setSpan_period(span_period);
        menstrualDayCalculate.setMenstrual_period(menstrual_period);
        menstrualDayCalculate.setDate(date);
        ovulatoryDayCalculate.setSpan_period(span_period);
        ovulatoryDayCalculate.setMenstrual_period(menstrual_period);
        ovulatoryDayCalculate.setDate(date);
        safeDayCalculate.setSpan_period(span_period);
        safeDayCalculate.setMenstrual_period(menstrual_period);
        safeDayCalculate.setDate(date);

        menstrualDayCalculate.setNextCalculate(ovulatoryDayCalculate);
        ovulatoryDayCalculate.setNextCalculate(safeDayCalculate);
    }

    public DayRecordBean calculate(@NonNull DayRecordBean request) {
        return menstrualDayCalculate.process(request);
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
        menstrualDayCalculate.setDate(date);
        ovulatoryDayCalculate.setDate(date);
        safeDayCalculate.setDate(date);
    }
}
